Xi-Language Reference: Color Manipulations

    • brighten (change an images saturation and value)
    • color_reduce (change the colors of an image)
    • dither (ordered dither for color images)
    • gammaCorr (performs gamma correction)
    • graymap (returns a grayscale colormap)
    • hsv2rgb (converts from HSV space to RGB space)
    • map2rgb (converts colormap based to RGB)
    • nonLinearFilters (non-linear filters)
    • rainbow (generates a rainbow colormap)
    • rgb2grayscale (convert a RGB image to a grayscale image)
    • rgb2hsv (converts from RGB space to HSV space)
    • rgb2map (converts from RGB to colormap based image)
    • rgb2yuv (converts from RGB space to Abekas YUV)
    • yuv2rgb (converts from Abekas YUV to RGB space)

    brighten (change an images saturation and value)

    Parameters

              brighten ( rgb, saturation = 100, value = 100 )
    
              Types: rgb                    char[]
                     saturation             int
                     value                  int
    

    Return

              char[]  (contains the image, RGB color system)
    

    Description

    The function brighten takes the image rgb (RGB colorsystem) as input. It converts the image from RGB space to HSV space and changes the value by \value as a percentage. The parameter \saturation works in the same way.

    Example

    >image=cincarr(25,25,3)
    >br=brighten(image, \saturation=20, \value=-10);
    

    See also

    rgb2hsv, hsv2rgb, gammaCorr

    Reference

    This function is based on the file ppmbrighten.c of the netpbm tools.
     **
     ** Copyright (C) 1989 by Jef Poskanzer.
     ** Copyright (C) 1990 by Brian Moffet.
     **
    

    color_reduce (change the colors of an image)

    Parameters

              color_reduce ( rgb, colormap = 0, colors = 0, floyd = 0 )
    
              Types: rgb                    char[]
                     colormap               char[]
                     colors                 int
                     floyd                  int
    

    Return

              char[]  (contains the image, RGB color system)
    

    Description

    The function color_reduce quantizes the colors in the image rgb down the specified number \colors or to the specified map \colormap. The quantization method is Heckbert's "median cut". The floyd flag enables a Floyd-Steinberg error diffusion step. Floyd-Steinberg gives vastly better results on images whereas the unmodified quantization has banding or other artifacts. However, it does take substantially more CPU time, so the default is off.

    Example

    >image=cincarr(50,500,3);
    >new1=color_reduce(image,\colors=255);
    >new2=color_reduce(image,\colormap=graymap(64),\floyd);
    

    See also

    dither, rgb2map, write_gif, write_pgm

    Reference

    This function is based on the file ppmquant.c of the netpbm tools.
     **
     ** Copyright (C) 1989, 1991 by Jef Poskanzer.
     **
    

    dither (ordered dither for color images)

    Parameters

              dither ( rgb, r = 5, g = 9, b = 5 )
    
              Types: rgb                    char[]
                     r                      char
                     g                      char
                     b                      char
    

    Return

              char[]  (contains the image, RGB color system)
    

    Description

    The function dither takes the image rgb as input and applies dithering to it in order to reduce the number of colors. The parameters r, g, b specify the number of shades for each primary color. The default number of shades is red=5, green=9, blue=5, for a total of 225 colors. The maximum number of colors that can be used is 256 and can be computed as the product of the number of red, green and blue shades.

    Example

    >image=cincarr(50,50,3);
    >new1=dither(image);
    >new2=dither(image,\r=2,\b=8);
    

    See also

    color_reduce, rgb2map

    Reference

    This function is based on the file ppmdither.c of the netpbm tools.
     **
     ** Copyright (C) 1991 by Christos Zoulas.
     **
    

    gammaCorr (performs gamma correction)

    Parameters

              gammaCorr ( image, r = 1.0, g = 1.0, b = 1.0 )
    
              Types: image                  char[]
                     r                      double
                     g                      double
                     b                      double
    

    Return

              char[]  (contains the image, RGB system)
    

    Description

    The function gammaCorr performs gamma corrections. The arguments r, g and b specify what gamma value(s) to use. A value of 1.0 leaves the image alone, less than 1.0 darkens it. Vice versa a value greater than 1.0 lightens it.

    Example

    >image=cincarr(10,10,3);
    >g=gammaCorr(image,\r=3.2,\b=1.0);
    

    See also

    brighten, rgb2hsv

    Reference

    This function is based on the file pnmgamma.c of the netpbm tools.
     **
     ** Copyright (C) 1991 by Bill Davidson and Jef Poskanzer.
     **
    

    graymap (returns a grayscale colormap)

    Parameters

              graymap ( length )
    
              Types: length                 int
    

    Return

              char[]  (contains the color map)
    

    Description

    The function graymap returns a grayscale color map with length entries.

    Example

    >print(graymap(3));
    <chrarr>
      0   0   0 
    127 127 127 
    255 255 255 
    

    See also

    rainbow, loadct

    hsv2rgb (converts from HSV space to RGB space)

    Parameters

              hsv2rgb ( hsv )
    
              Types: hsv                    double[]
    

    Return

              char[]  (contains the image/colormap, RGB system)
    

    Description

    The function hsv2rgb converts an image/colormap from the HSV space to the RGB system. hsv has to three cloumns. The first of the three columns contains the hue variables in the range of 0 to 360. It distinguish between the colors, with red at 0 degress, green at 120 and blue at 240 degrees. The second column are the saturation variables refers to how pure the color is (range 0.0 to 1.0) and the third column contains the value variables, corresponds to the intensity (range also 0.0 to 1.0).

    Example

    >hsv_colorTable=transpose({interval(0,360,40), darr(40)+0.5, darr(40)+0.5 });
    Function interval defined
    >rainbow=hsv2rgb(hsv_colorTable);  
    

    See also

    rgb2hsv, brighten

    Reference

    This function is based on the file ppmbrighten.c of the netpbm tools.
     **
     ** Copyright (C) 1989 by Jef Poskanzer.
     ** Copyright (C) 1990 by Brian Moffet.
     **
    

    map2rgb (converts colormap based to RGB)

    Parameters

              map2rgb ( image, colormap )
    
              Types: image                  char[]
                     colormap               char[]
    

    Return

              char[]  (contains the image, RGB system)
    

    Description

    The function map2rgb converts a colormap based image to the RGB system. The two dimensional array image contains the image and colormap determines the corresponding colormap.

    Example

    >graymap=graymap(256);
    >pixmap =cincarr(200,200,3);
    >rgb    =map2rgb(pixmap, graymap);
    

    See also

    rgb2map

    nonLinearFilters (non-linear filters)

    Parameters

              nonLinearFilters ( image, alpha = 1.0, radius = 0.5 )
    
              Types: image                  char[]
                     alpha                  double
                     radius                 double
    

    Return

              char[]  (contains the image, RGB system)
    

    Description

    The function nonLinearFilters is something of a swiss army knife filter. It has 3 distinct operating modes. In all of the modes each pixel in the image is examined and processed according to it and its surrounding pixels values. Rather than using the 9 pixels in a 3x3 block, 7 hexagonal area samples are taken, the size of the hexagons being controlled by the radius parameter.A \radius value of 0.3333 means that the 7 hexagons exactly fit into the center pixel (ie. there will be no filtering effect). A radius value of 1.0 means that the 7 hexagons exactly fit a 3x3 pixel array. (0.0 <= alpha <= 0.5) Alpha trimmed mean filter. The value of the center pixel will be replaced by the mean of the 7 hexagon values, but the 7 values are sorted by size and the top and bottom alpha portion of the 7 are excluded from the mean. This implies that an alpha value of 0.0 gives the same sort of output as a normal convolution (ie. averaging or smoothing filter), where radius will determine the "strength" of the filter. An alpha value of 0.5 will cause the median value of the 7 hexagons to be used to replace the center pixel value. This sort of filter is good for eliminating "pop" or single pixel noise from an image without spreading the noise out or smudging features on the image. Judicious use of the radius parameter will fine tune the filtering. (1.0 <= alpha <= 2.0) Optimal estimation smoothing. This type of filter applies a smoothing filter adaptively over the image. For each pixel the variance of the surrounding hexagon values is calculated, and the amount of smoothing is made inversely proportional to it. The idea is that if the variance is small then it is due to noise in the image, while if the variance is large, it is because of wanted image features. You could start with values like alpha = 1.2, radius = 1.0 and try increasing or decreasing the alpha parameter to get the desired effect. This type of filter is best for filtering out dithering noise in both bitmap and color images. (-0.1 >= alpha >= -0.9) Edge enhancement. This is the opposite type of filter to the smoothing filter. It enhances edges. The alpha parameter controls the amount of edge enhancement, from subtle (-0.1) to blatant (-0.9). The radius parameter controls the effective radius as usual, but useful values are between 0.5 and 0.9. Try starting with values of alpha = 0.3, radius = 0.8 Combination use. To turn a monochrome dithered image into a grayscale image you could try one or two passes of the smoothing filter, followed by a pass of the optimal estimation filter, then some subtle edge enhancement. For reducing color quantization noise in images (ie. turning .gif files back into 24 bit files) you could try a pass of the optimal estimation filter (alpha 1.2, radius 1.0), a pass of the median filter (alpha 0.5, radius 0.55), and possibly a pass of the edge enhancement filter.

    Example

    >image=cincarr(10,10,3);
    >g=nonLinearFilters(image,\alpha=0.3,\radius=0.9);
    

    See also

    brighten, color_reduce, smooth

    Reference

    This function is based on the file pnmnlfilt.c of the netpbm tools.
     **
     ** Author: Graeme W. Gill, 30th Jan 1993
     **         graeme@labtam.oz.au
     **
    

    rainbow (generates a rainbow colormap)

    Parameters

              rainbow ( n = 255, s = 0.8, v = 0.8 )
    
              Types: n                      int
                     s                      double
                     v                      double
    

    Return

              char[]  (contains the colormap)
    

    Description

    The function rainbow produces a rainbow colormap with n entries, the saturation (determines how pure a color is) s and the value (intensity of the color) v.

    Example

    >rainbowMap=rainbow();
    Function rainbow defined
    >loadct(rainbow(126,0.4,0.4));
    >window(0,\bpp=7);
    >show(cincarr(126,1)+2);
    

    See also

    graymap, loadct

    rgb2grayscale (convert a RGB image to a grayscale image)

    Parameters

              rgb2grayscale ( rgb, r = 0.299, g = 0.587, b = 0.114 )
    
              Types: rgb                    char[]
                     r                      double
                     g                      double
                     b                      double
    

    Return

              char[]  (contains the image, two dimensional array)
    

    Description

    The function rgb2grayscale converts a RGB image to a grayscale image. The parameters r, g and b contain the weights for the colors red, green and blue.

    Example

    >image=cincarr(20,20,3);
    >g1=rgb2grayscale(image);
    >g2=rgb2grayscale(image,\r=0.5,\g=0.2,\b=0.3);
    >write_gif("test.gif",g1,graymap(256));
    

    See also

    graymap, rgb2map, map2rgb

    rgb2hsv (converts from RGB space to HSV space)

    Parameters

              rgb2hsv ( rgb )
    
              Types: rgb                    char[]
    

    Return

              double[]  (contains the image/colormap, HSV system)
    

    Description

    The function hsv2rgb converts an image/colormap from the RGB space to the HSV system. The return value has three columns. The first of the three columns contains the hue variables in the range of 0 to 360. It distinguishes between the colors with red at 0 degress, green at 120 and blue at 240 degrees. The second column contains the saturation variables which determine the pureness of the color (range 0.0 to 1.0). The third column contains the value variables which correspond to the intensity (range also 0.0 to 1.0).

    Example

    >image=cincarr(20,20,3);
    >hsv=rgb2hsv(image);
    >rgb=hsv2rgb(hsv);
    

    See also

    hsv2rgb, brighten

    Reference

    This function is based on the file ppmbrighten.c of the netpbm tools.
     **
     ** Copyright (C) 1989 by Jef Poskanzer.
     ** Copyright (C) 1990 by Brian Moffet.
     **
    

    rgb2map (converts from RGB to colormap based image)

    Parameters

              rgb2map ( rgb, maxcolors = 256 )
    
              Types: rgb                    char[]
                     maxcolors              char
    

    Return

              [char[],char[]]  (returns the pixelmap and colormap)
    

    Description

    The function rgb2map converts a RGB image to an colormap based image. The first return value contains the pixelmap the second contains the colormap.

    Example

    >image=cincarr(20,20,3);
    >[pixmap, colormap]=rgb2map(image);
    >rgb=map2rgb(pixmap,colormap);
    

    See also

    map2rgb

    Reference

    This function is based on the the netpbm tools.

    rgb2yuv (converts from RGB space to Abekas YUV)

    Parameters

              rgb2yuv ( rgb )
    
              Types: rgb                    char[]
    

    Return

              char[]  (contains the image)
    

    Description

    The function rgb2yuv converts an image from RGB space to the Abekas YUV system. We have encountered problems with this one - use it with care! We are not sure yet wheter the NETPBM function or in <B>Xi</B> carries the can.

    Example

    >image=cincarr(20,20,3);
    >yuv=rgb2yuv(image);
    >rgb=yuv2rgb(yuv);
    

    See also

    yuv2rgb

    Reference

    This function is based on the file ppmtoyuv.c of the netpbm tools.
     **
     ** by Marc Boucher
     ** Internet: marc@PostImage.COM
     **
     ** Based on Example Conversion Program, A60/A64 Digital Video Interface
     ** Manual, page 69.
     **
     ** Copyright (C) 1991 by DHD PostImage Inc.
     ** Copyright (C) 1987 by Abekas Video Systems Inc.
     **
    

    yuv2rgb (converts from Abekas YUV to RGB space)

    Parameters

              yuv2rgb ( rgb )
    
              Types: rgb                    char[]
    

    Return

              char[]  (contains the image)
    

    Description

    The function yuv2rgb converts an image from the Abekas YUV system to RGB space. We have encountered problems with this one - use it with care! We are not sure yet wheter the error is lying in the underlying NETPBM function or in <B>Xi</B>.

    Example

    >image=cincarr(20,20,3);
    >yuv=rgb2yuv(image);
    >rgb=yuv2rgb(yuv);
    

    See also

    rgb2yuv

    Reference

    This function is based on the file yuvtoppm.c of the netpbm tools.
     **
     ** by Marc Boucher
     ** Internet: marc@PostImage.COM
     **
     ** Based on Example Conversion Program, A60/A64 Digital Video Interface
     ** Manual, page 69
     **
     ** Uses integer arithmetic rather than floating point for better performance
     **
     ** Copyright (C) 1991 by DHD PostImage Inc.
     ** Copyright (C) 1987 by Abekas Video Systems Inc.
     ** Copyright (C) 1991 by Jef Poskanzer.
     **
    

    © 1995 by Bodo Junglas, Klaus Spanderen and Fabian Weis
    - Last revised: Wed Jun 19 16:58:32 1996